package com.playball.lottery.frm.yhzx;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.playball.lottery.R;
import com.playball.lottery.ApplicationData;
import com.playball.lottery.base.BaseActivity;
import com.playball.lottery.customview.BallDTO;
import com.playball.lottery.customview.PullDownView;
import com.playball.lottery.customview.ShowTipDialog;
import com.playball.lottery.customview.PullDownView.OnPullDownListener;
import com.playball.lottery.frm.buyhall.SsqxhActivity;
import com.playball.lottery.frm.buyhall.SsqxhlbActivity;
import com.playball.lottery.nt.GetRequestParams;
import com.playball.lottery.util.Constants;
import com.playball.lottery.util.ConvertJsonToList;
import com.playball.lottery.util.DefConstants;
import com.playball.lottery.util.Logger;
import com.playball.lottery.util.LotUtil;
import com.playball.lottery.util.PreferencesUtils;


/**
 * 投注记录
 * 
 * @author Administrator
 * 
 */
public class BetRecordActivity extends BaseActivity implements OnPullDownListener, DefConstants {
	/** 上下文内容 */
	private Context context = null;
	// 彩种编号
	private int lotID = 0;
	// 显示页号
	private int pageNo = 1;
	// 显示页数
	private int pageSize = 10;
	// 是否有下一页
	private boolean nextPage;
	/** 记录总条数 */
	private int intTotalNum;
	private HorizontalScrollView hScrollView;
	/** 菜单按钮视图 */
	private View vBtn;
	/** ScrollView是否被用户拖动 */
	private boolean isonTouch = false;
	/** 控制ScrollView */
	private final Handler mHandler = new Handler();
	/** 自定义下拉刷新组件 **/
	private PullDownView mPullDownView;
	/** 投注记录listview视图 */
	private ListView yhzx_lv_betrecord;
	/** 是否按更多 */
	private boolean isPressMore = false;
	/** 填充到listview的本地数据 */
	private List<Map<String, Object>> mDataList;
	/** 网络获取的数据 */
	private List<Map<String, Object>> netDataList;
	/** 投注记录适配器 */
	private BetRecordListAdapter recordAdapter;
	
	private LinearLayout linlay;
	private Button btn_Buy;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		this.context = this;
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.yhzx_betrecord);
		// 获得传来的lotID
		Intent intent = getIntent();
		lotID = intent.getIntExtra("lotID", 0);
		initView();

		hScrollView = (HorizontalScrollView) findViewById(R.id.yhzx_scrollview);

		// 启动获取记录数据线程
		startRecordThread();

		setBtnOnClick(R.id.yhzx_betrecord_all);
		setBtnOnClick(R.id.yhzx_betrecord_ssq);
		setBtnOnClick(R.id.yhzx_betrecord_dlt);
		setBtnOnClick(R.id.yhzx_betrecord_11x5);
		setBtnOnClick(R.id.yhzx_betrecord_kuai3);
		setBtnOnClick(R.id.yhzx_betrecord_11ydj);
		setBtnOnClick(R.id.yhzx_betrecord_cqssc);
		setBtnOnClick(R.id.yhzx_betrecord_jc);
		setBtnOnClick(R.id.yhzx_betrecord_pl3);
		setBtnOnClick(R.id.yhzx_betrecord_pl5);
		setBtnOnClick(R.id.yhzx_betrecord_fc3d);
		setBtnOnClick(R.id.yhzx_betrecord_sfc);
		setBtnOnClick(R.id.yhzx_betrecord_rx9);
		setBtnOnClick(R.id.yhzx_betrecord_jclq);
		setBtnOnClick(R.id.yhzx_betrecord_bd);
		setBtnOnClick(R.id.yhzx_betrecord_ql);
		setBtnOnClick(R.id.yhzx_betrecord_qx);
		setBtnOnClick(R.id.yhzx_betrecord_lhc);
		setBtnOnClick(R.id.yhzx_betrecord_animal);

		hScrollView.setOnTouchListener(new OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent event) {
				isonTouch = true;
				View view = (View) hScrollView.getChildAt(hScrollView.getChildCount() - 1);
				int subViewWidth = view.getRight();
				int x = hScrollView.getScrollX();
				return false;
			}
		});
		
		btn_Buy.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				PreferencesUtils pUtil = new PreferencesUtils(BetRecordActivity.this, Constants.PREFERENCES_NAME);
				Intent intent = new Intent();
				int ssq_size = pUtil.getInt("ssq_size", 0);
				if (ssq_size != 0) {
					ArrayList<BallDTO> list = new ArrayList<BallDTO>();
					for (int i = 0; i < ssq_size; i++) {
						BallDTO ball = new BallDTO();
						ball.setSsq_ball(pUtil.getString("ssq_ball" + i, ""));
						list.add(ball);
					}
					intent.putExtra("list_ssqdto", list);
					intent.putExtra("AllMoney", pUtil.getInt("ssq_allMoney", 0));
					intent.setClass(BetRecordActivity.this, SsqxhlbActivity.class);
					Toast.makeText(BetRecordActivity.this, R.string.this_is_the_last_time_you_save_the_number,
							Toast.LENGTH_SHORT).show();
				} else {
					intent.setClass(BetRecordActivity.this, SsqxhActivity.class);
				}
				startActivity(intent);
			}
		});

	}

	public void onResume() {
		super.onResume();
		
	}

	public void onPause() {
		super.onPause();
		
	}

	class AsyncLoader extends AsyncTask<String, Integer, String> {// 继承AsyncTask

		String action;

		ShowTipDialog showdialog = new ShowTipDialog();

		// 1.准备运行
		protected void onPreExecute() {
			showdialog.showDialog(BetRecordActivity.this);
		}

		// 2.正在后台运行
		@Override
		protected String doInBackground(String... paramsArr) {
			// 处理后台执行的任务，在后台线程执行
			String strResult = null;

			action = paramsArr[1];
			String UserID = ApplicationData.getInstance().getUserID();
			strResult = GetRequestParams.getRequestUserIDResult(paramsArr[0], UserID, action, getApplicationContext());
			System.out.println("result is " + strResult);
			// 获取请求返回值
			return strResult;
		}

		// 3.进度更新
		protected void onProgressUpdate(Integer... progress) {
		}

		// 4.完成后台任务
		protected void onPostExecute(String result) {
			if (result != null) {
				// System.out.println(result);
				try {
					JSONTokener jsonParser = new JSONTokener(result);
					JSONObject js = (JSONObject) jsonParser.nextValue();
					// 接下来的就是JSON对象的操作了
					if (Integer.parseInt(js.getString("Code")) == 0) {
						try {
							JSONTokener jsonParser1 = new JSONTokener(result);
							JSONObject js1 = (JSONObject) jsonParser1.nextValue();
							if (js1.getString("Data") != null && !"".equals(js1.getString("Data"))) {
								
								String Count = String.valueOf(ConvertJsonToList.getMap(js1.getString("Data")).get(
										"Count"));
								intTotalNum = Integer.parseInt(Count);
								List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
								list = ConvertJsonToList.getList(String.valueOf(ConvertJsonToList.getMap(
										js1.getString("Data")).get("item")));
								netDataList = new ArrayList<Map<String, Object>>(list);
								if(list !=null)
								{
									if(list.size()>0)
									{
										mPullDownView.setVisibility(View.VISIBLE);
										linlay.setVisibility(View.GONE);
									}else{
										mPullDownView.setVisibility(View.GONE);
										linlay.setVisibility(View.VISIBLE);
									}
								}
							} else {
								// 数据为空时为0
								intTotalNum = 0;
								if (netDataList != null) {
									netDataList.clear();
								}
								mPullDownView.setVisibility(View.GONE);
								linlay.setVisibility(View.VISIBLE);
							}
						} catch (JSONException e) {
							// 异常处理代码
							Log.e("error", e.toString());
						}
						// 显示
						showBRList();
						// 改变ScrollView的初始化定位位置
						if (!isonTouch) {
							mHandler.post(mScrollToButton);// 传递一个消息进行滚动
						}
					} else {
						Toast.makeText(BetRecordActivity.this, js.getString("Data"), Toast.LENGTH_SHORT).show();
					}
				} catch (JSONException ex) {
					// 异常处理代码
					Log.e("error", ex.toString());
				} finally {
					showdialog.closeDialog();
				}
			} else {
				Toast.makeText(BetRecordActivity.this, getString(R.string.problem_01), Toast.LENGTH_LONG).show();
			}
		}

		// 5.完成后操作
		protected void onCancelled() {
		}

	}

	public void startRecordThread() {
		AsyncLoader task = new AsyncLoader();

		String[] dyn = new String[2];
		JSONObject params = new JSONObject();
		try {
			params.put("LotID", lotID);
			params.put("PageNo", pageNo);
			params.put("PageSize", pageSize);
		} catch (JSONException ex) {
			Log.e("error", ex.toString());
		}
		dyn[0] = params.toString();
		// 投注记录
		// dyn[1] = "10111";//10111 简易版， 111完整版
		dyn[1] = "111";//10111 简易版， 111完整版
		task.execute(dyn);
	}

	private void initView() {
		/*
		 * 1.使用PullDownView 2.设置OnPullDownListener 3.从mPullDownView里面获取ListView
		 */
		
		linlay=(LinearLayout)findViewById(R.id.linLay);
		btn_Buy=(Button)findViewById(R.id.btn_Buy);
		
		mPullDownView = (PullDownView) findViewById(R.id.yhzx_lv_betrecord);

		mPullDownView.setOnPullDownListener(this);

		yhzx_lv_betrecord = mPullDownView.getListView();

		// 标题
		titleBar();
	}

	/**
	 * 程序控制ScrollView滚动到指定位置
	 */
	private Runnable mScrollToButton = new Runnable() {
		public void run() {
			// 使用scrollView.scrollTo(x, y)滚动到某个位置，如scrollView.scrollTo(0,
			// 0)表示滚动到顶部
			final float scale = context.getResources().getDisplayMetrics().density;
			// android:layout_marginLeft="2dp"
			int mlpx = (int) (2 * scale + 0.5f);
			// int arrowpx=leftArrow.getRight();
			int arrowpx = 0;
			int vLeft = vBtn.getLeft();
			hScrollView.scrollTo(vLeft - (mlpx + arrowpx), 0);
		}
	};

	/** 刷新事件接口 这里要注意的是刷新完 要关闭 刷新的进度条RefreshComplete() **/
	@Override
	public void onRefresh() {

		// 发送刷新请求
		pageNo = 1;
		startRecordThread();

	}

	/** 更多事件接口 这里要注意的是获取更多完 要关闭 更多的进度条 notifyDidMore() **/
	@Override
	public void onMore() {
		isPressMore = true;
		pageNo += 1;
		startRecordThread();
	}

	/**
	 * 放入数据，显示listview视图
	 */
	public void showBRList() {
		int maxPage = (intTotalNum % pageSize == 0) ? (intTotalNum / pageSize) : (intTotalNum / pageSize + 1);
		Log.d("maxPage", maxPage + "");
		if (pageNo < maxPage) {
			nextPage = true;
		} else {
			nextPage = false;
		}
		Log.v("nextPage= ", nextPage + "");
		// //获取更多数据之外的请求:首次请求数据
		if (!isPressMore) {

			mDataList = netDataList;
			// 填充UI,listview
			if (mDataList != null) {
				recordAdapter = new BetRecordListAdapter(mDataList);
				yhzx_lv_betrecord.setAdapter(recordAdapter);
			}
			// 隐藏并且禁用头部刷新
			mPullDownView.setHideHeader();
			// 显示并且可以使用头部刷新
			mPullDownView.setShowHeader();

			/** 关闭 刷新完毕 ***/
			mPullDownView.RefreshComplete();// 这个事线程安全的 可看源代码

		} else {
			// 获取更多数据
			mDataList.addAll(netDataList);
			recordAdapter.notifyDataSetChanged();

		}
		if (mDataList == null) {
			Toast.makeText(context, R.string.temporarily_no_data, Toast.LENGTH_LONG).show();
		}
		// 判断是否有下一页
		if (nextPage) {
			// 显示并启用自动获取更多
			mPullDownView.setShowFooter();
			// 设置可以自动获取更多 滑到最后一个自动获取 改成false将禁用自动获取更多
			mPullDownView.enableAutoFetchMore(true, 1);
		} else {
			// 隐藏 并禁用尾部
			mPullDownView.setHideFooter();
			// 设置可以自动获取更多 滑到最后一个自动获取 改成false将禁用自动获取更多
			mPullDownView.enableAutoFetchMore(false, 1);
		}
		// 告诉它获取更多完毕 这个事线程安全的 可看源代码
		mPullDownView.notifyDidMore();
		isPressMore = false;

	}

	// 对返回数据进行修改
	public List<Map<String, Object>> modifyData(List<Map<String, Object>> data) {
		if (data != null) {
			for (int i = 0; i < data.size(); i++) {
				String issue = data.get(i).get("Issue").toString();
				String money = data.get(i).get("Money").toString();
				String win = data.get(i).get("WinMoney").toString();
				if (win.matches("\\d*")) {
					win = Float.parseFloat(win) + "彩豆";
				}
				issue += "期";
				money += "彩豆";
				data.get(i).put("Issue", issue);
				data.get(i).put("Money", money);
				data.get(i).put("WinMoney", win);
			}
		}
		return data;
	}

	private void setBtnOnClick(final int btnId) {
		Button btn = (Button) findViewById(btnId);
		btn.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				pageNo = 1;
				pageSize = 10;
				recordAdapter = new BetRecordListAdapter(new ArrayList<Map<String, Object>>());
				lotID = getLotID(btnId);
				startRecordThread();
			}
		});

	}

	public int getLotID(int btnId) {
		int id = 0;
		// 恢复默认
		((Button) findViewById(R.id.yhzx_betrecord_all)).setEnabled(true);
		((Button) findViewById(R.id.yhzx_betrecord_ssq)).setEnabled(true);// setBackgroundResource(R.drawable.yhzx_retrecord_center01);
		((Button) findViewById(R.id.yhzx_betrecord_dlt)).setEnabled(true);// setBackgroundResource(R.drawable.yhzx_retrecord_center01);
		((Button) findViewById(R.id.yhzx_betrecord_11x5)).setEnabled(true);// setBackgroundResource(R.drawable.yhzx_retrecord_center01);
		((Button) findViewById(R.id.yhzx_betrecord_kuai3)).setEnabled(true);
		((Button) findViewById(R.id.yhzx_betrecord_11ydj)).setEnabled(true);
		((Button) findViewById(R.id.yhzx_betrecord_cqssc)).setEnabled(true);
		((Button) findViewById(R.id.yhzx_betrecord_jc)).setEnabled(true);// setBackgroundResource(R.drawable.yhzx_betrecord_right01);
		((Button) findViewById(R.id.yhzx_betrecord_fc3d)).setEnabled(true);
		((Button) findViewById(R.id.yhzx_betrecord_pl3)).setEnabled(true);
		((Button) findViewById(R.id.yhzx_betrecord_pl5)).setEnabled(true);
		((Button) findViewById(R.id.yhzx_betrecord_sfc)).setEnabled(true);
		((Button) findViewById(R.id.yhzx_betrecord_rx9)).setEnabled(true);
		((Button) findViewById(R.id.yhzx_betrecord_jclq)).setEnabled(true);
		((Button) findViewById(R.id.yhzx_betrecord_bd)).setEnabled(true);
		((Button) findViewById(R.id.yhzx_betrecord_qx)).setEnabled(true);
		((Button) findViewById(R.id.yhzx_betrecord_ql)).setEnabled(true);
		((Button) findViewById(R.id.yhzx_betrecord_lhc)).setEnabled(true);
		switch (btnId) {
			case R.id.yhzx_betrecord_lhc:
				id = 96;
				((Button) findViewById(R.id.yhzx_betrecord_lhc)).setEnabled(false);
				break;
		case R.id.yhzx_betrecord_all:
			id = 0;
			((Button) findViewById(R.id.yhzx_betrecord_all)).setEnabled(false);// setBackgroundResource(R.drawable.yhzx_retrecord_left02);
			break;
		case R.id.yhzx_betrecord_ssq:
			id = 5;
			((Button) findViewById(R.id.yhzx_betrecord_ssq)).setEnabled(false);// setBackgroundResource(R.drawable.yhzx_retrecord_center02);
			break;
		case R.id.yhzx_betrecord_dlt:
			id = 39;
			((Button) findViewById(R.id.yhzx_betrecord_dlt)).setEnabled(false);// setBackgroundResource(R.drawable.yhzx_retrecord_center02);
			break;
		case R.id.yhzx_betrecord_11x5:
			id = 70;
			((Button) findViewById(R.id.yhzx_betrecord_11x5)).setEnabled(false);// setBackgroundResource(R.drawable.yhzx_retrecord_center02);
			break;
		case R.id.yhzx_betrecord_kuai3:
			id = 66;
			((Button) findViewById(R.id.yhzx_betrecord_kuai3)).setEnabled(false);
			break;
		case R.id.yhzx_betrecord_11ydj:
			id = 62;
			((Button) findViewById(R.id.yhzx_betrecord_11ydj)).setEnabled(false);
			break;
		case R.id.yhzx_betrecord_cqssc:
			id = 28;
			((Button) findViewById(R.id.yhzx_betrecord_cqssc)).setEnabled(false);
			break;
		case R.id.yhzx_betrecord_jc:
			id = 90;
			((Button) findViewById(R.id.yhzx_betrecord_jc)).setEnabled(false);// setBackgroundResource(R.drawable.yhzx_betrecord_right02);
			break;
		case R.id.yhzx_betrecord_fc3d:
			id = 6;
			((Button) findViewById(R.id.yhzx_betrecord_fc3d)).setEnabled(false);
			break;
		case R.id.yhzx_betrecord_pl3:
			id = 63;
			((Button) findViewById(R.id.yhzx_betrecord_pl3)).setEnabled(false);
			break;
		case R.id.yhzx_betrecord_pl5:
			id = 64;
			((Button) findViewById(R.id.yhzx_betrecord_pl5)).setEnabled(false);
			break;
		case R.id.yhzx_betrecord_sfc:
			id = 1;
			((Button) findViewById(R.id.yhzx_betrecord_sfc)).setEnabled(false);
			break;
		case R.id.yhzx_betrecord_rx9:
			id = 19;
			((Button) findViewById(R.id.yhzx_betrecord_rx9)).setEnabled(false);
			break;
		case R.id.yhzx_betrecord_jclq:
			id = 91;
			((Button) findViewById(R.id.yhzx_betrecord_jclq)).setEnabled(false);
			break;
		case R.id.yhzx_betrecord_bd:
			id = LOT_ID_BD;
			((Button) findViewById(R.id.yhzx_betrecord_bd)).setEnabled(false);
			break;
		case R.id.yhzx_betrecord_ql:
			id = LOT_ID_QLC;
			((Button) findViewById(R.id.yhzx_betrecord_ql)).setEnabled(false);
			break;
		case R.id.yhzx_betrecord_qx:
			id = LOT_ID_QXC;
			((Button) findViewById(R.id.yhzx_betrecord_qx)).setEnabled(false);
			break;
		case R.id.yhzx_betrecord_animal:
			id = LOT_ID_ANIMAL;
			((Button) findViewById(R.id.yhzx_betrecord_animal)).setEnabled(false);
			break;
		}
		return id;
	}

	/**
	 * 投注记录listview适配器
	 * 
	 * @author Administrator
	 * 
	 */
	public class BetRecordListAdapter extends BaseAdapter {
		/** 投注记录listview数据 */
		private List<Map<String, Object>> mData;
		private LayoutInflater mInflater;

		public BetRecordListAdapter(List<Map<String, Object>> appData) {
			mData = appData;
			this.mInflater = LayoutInflater.from(context);
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return mData.size();
		}

		@Override
		public Object getItem(int arg0) {
			// TODO Auto-generated method stub
			return mData.get(arg0);
		}

		@Override
		public long getItemId(int arg0) {
			// TODO Auto-generated method stub
			return arg0;
		}

		public View getView(final int position, View convertView, final ViewGroup parent) {
			// System.out.println("br BetRecordListAdapter getView " + position
			// + " " + convertView);
			ViewHolder holder = null;
			if (convertView == null) {
				holder = new ViewHolder();
				convertView = mInflater.inflate(R.layout.yhzx_betrecord_list, null);
				holder.yhzx_betrecord_ll_total = (LinearLayout) convertView.findViewById(R.id.yhzx_betrecord_ll_total);
				holder.tvLotName = (TextView) convertView.findViewById(R.id.yhzx_betrecord_lottery_type);
				holder.tvIssue = (TextView) convertView.findViewById(R.id.yhzx_betrecord_issue);
				holder.tvMoney = (TextView) convertView.findViewById(R.id.yhzx_betrecord_money);
				holder.tvState = (TextView) convertView.findViewById(R.id.yhzx_betrecord_status);
				holder.tvWin = (TextView) convertView.findViewById(R.id.yhzx_betrecord_zjje);
				holder.imageView1 = (ImageView) convertView.findViewById(R.id.imageView1);
//				holder.yhzx_betrecord_time = (TextView) convertView.findViewById(R.id.yhzx_betrecord_time);
//				holder.yhzx_betrecord_hemaiorzigou = (TextView) convertView.findViewById(R.id.yhzx_betrecord_hemaiorzigou);
				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			// 彩种
			holder.tvLotName.setText(mData.get(position).get("LotName").toString());
			// 期号
			holder.tvIssue.setText(mData.get(position).get("Issue").toString());
			// System.out.println("111111"+mData.get(position).get("Issue").toString());
			// 投注金额
			holder.tvMoney.setText(mData.get(position).get("Money").toString());
			// 状态
			holder.tvState.setText(mData.get(position).get("State").toString());
			// 中奖金额
			String WinMoney = mData.get(position).get("WinMoney").toString();
			if ("未中奖".equals(WinMoney)) {
				holder.tvWin.setBackgroundColor(getResources().getColor(R.color.ui_new_divider_bg));
			} else if ("未开奖".equals(WinMoney)) {
				holder.tvWin.setBackgroundColor(getResources().getColor(R.color.ui_new_btn_no_normal_solid));
			} else if ("中奖啦".equals(WinMoney)) {
				holder.tvWin.setBackgroundColor(getResources().getColor(R.color.ui_txt_color_selected_red));
			} else {
				holder.tvWin.setBackgroundColor(getResources().getColor(R.color.ui_new_divider_bg));
			}
			holder.tvWin.setTextColor(getResources().getColor(R.color.white));
			holder.tvWin.setText(WinMoney);

			String mState = mData.get(position).get("State").toString();
			if (mState.indexOf("撤单") > 0 || mState.indexOf("未满员") >= 0) {
				// holder.tvWin.setVisibility(View.INVISIBLE);
				holder.tvWin.setBackgroundColor(getResources().getColor(R.color.transparent));
				holder.tvWin.setTextColor(getResources().getColor(R.color.ui_new_hemai_txt));
				holder.tvWin.setText("-");
			}

			holder.imageView1.setImageResource(LotUtil
					.getLotIconIDByName(mData.get(position).get("LotName").toString()));

			holder.yhzx_betrecord_ll_total.setOnClickListener(new View.OnClickListener() {
				public void onClick(View v) {
					Intent intent;
					intent = new Intent(BetRecordActivity.this, PlanDetailsActivity.class);
					intent.putExtra("SchemeID", mData.get(position).get("ID").toString());
					intent.putExtra("LotName", mData.get(position).get("LotName").toString());
					intent.putExtra("DataSource", "1"/*mData.get(position).get("DataSource").toString()*/);
					startActivityForResult(intent, 910);
				}
			});

//			holder.yhzx_betrecord_time.setText(mData.get(position).get("DateTime").toString());
//			String SchemeType = mData.get(position).get("SchemeType").toString();
//			String hemaiorzigou = "-";
//			if ("1".equals(SchemeType)) {
//				hemaiorzigou = "自购";
//			} else if ("2".equals(SchemeType)) {
//				hemaiorzigou = "合买";
//			} else if ("3".equals(SchemeType)) {
//				hemaiorzigou = "保存";
//			}
//			holder.yhzx_betrecord_hemaiorzigou.setText(hemaiorzigou);
			return convertView;
		}

		public class ViewHolder {
			// 线性布局
			public LinearLayout yhzx_betrecord_ll_total;
			public TextView tvLotName;
			public TextView tvIssue;
			public TextView tvMoney;
			public TextView tvState;
			public TextView tvWin;
			public ImageView imageView1;
//			public TextView yhzx_betrecord_time;
//			public TextView yhzx_betrecord_hemaiorzigou;
		}
	}

	// TitleBar标题栏
	public void titleBar() {
		Button back = (Button) findViewById(R.id.top_title_back);
		// back.getBackground().setAlpha(255);// 透明度0~255透明度值 ，值越小越透明
		// back.setVisibility(View.INVISIBLE);
		back.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();
			}
		});

		TextView info = (TextView) findViewById(R.id.top_title_info);
		info.setText("投注记录");
		if (lotID == 0) {
			vBtn = ((Button) findViewById(R.id.yhzx_betrecord_all));
			vBtn.setEnabled(false);

		} else if (lotID == LOT_ID_SSQ) {
			vBtn = ((Button) findViewById(R.id.yhzx_betrecord_ssq));
			vBtn.setEnabled(false);

		} else if (lotID == LOT_ID_DLT) {
			vBtn = ((Button) findViewById(R.id.yhzx_betrecord_dlt));
			vBtn.setEnabled(false);

		} else if (lotID == LOT_ID_11X5) {
			vBtn = ((Button) findViewById(R.id.yhzx_betrecord_11x5));
			vBtn.setEnabled(false);

		} else if (lotID == LOT_ID_KUAI3) {
			vBtn = ((Button) findViewById(R.id.yhzx_betrecord_kuai3));
			vBtn.setEnabled(false);

		} else if (lotID == LOT_ID_11YDJ) {
			vBtn = ((Button) findViewById(R.id.yhzx_betrecord_11ydj));
			vBtn.setEnabled(false);

		} else if (lotID == LOT_ID_CQSSC) {
			vBtn = ((Button) findViewById(R.id.yhzx_betrecord_cqssc));
			vBtn.setEnabled(false);

		} else if (lotID == LOT_ID_JCZQ) {
			vBtn = ((Button) findViewById(R.id.yhzx_betrecord_jc));
			vBtn.setEnabled(false);

		} else if (lotID == LOT_ID_FC3D) {
			vBtn = ((Button) findViewById(R.id.yhzx_betrecord_fc3d));
			vBtn.setEnabled(false);

		} else if (lotID == LOT_ID_PL3) {
			vBtn = ((Button) findViewById(R.id.yhzx_betrecord_pl3));
			vBtn.setEnabled(false);

		} else if (lotID == LOT_ID_PL5) {
			vBtn = ((Button) findViewById(R.id.yhzx_betrecord_pl5));
			vBtn.setEnabled(false);

		} else if (lotID == LOT_ID_ZQ_SFC) {
			vBtn = ((Button) findViewById(R.id.yhzx_betrecord_sfc));
			vBtn.setEnabled(false);

		} else if (lotID == LOT_ID_ZQ_RX9) {
			vBtn = ((Button) findViewById(R.id.yhzx_betrecord_rx9));
			vBtn.setEnabled(false);

		} else if (lotID == LOT_ID_JCLQ) {
			vBtn = ((Button) findViewById(R.id.yhzx_betrecord_jclq));
			vBtn.setEnabled(false);

		} else if (lotID == LOT_ID_BD) {
			vBtn = ((Button) findViewById(R.id.yhzx_betrecord_bd));
			vBtn.setEnabled(false);

		} else if (lotID == LOT_ID_QLC) {
			vBtn = ((Button) findViewById(R.id.yhzx_betrecord_ql));
			vBtn.setEnabled(false);

		} else if (lotID == LOT_ID_QXC) {
			vBtn = ((Button) findViewById(R.id.yhzx_betrecord_qx));
			vBtn.setEnabled(false);

		}else if(lotID == LOT_ID_LHC){
			vBtn =  ((Button) findViewById(R.id.yhzx_betrecord_lhc));
			vBtn.setEnabled(false);
		}
		Button refres = (Button) findViewById(R.id.top_title_refres);
		// refres.getBackground().setAlpha(155);// 透明度0~255透明度值 ，值越小越透明
		refres.setVisibility(View.INVISIBLE);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			this.finish();
			return true;
		} else {
			return super.onKeyDown(keyCode, event);
		}

	};

	@Override
	public void finish() {
		// TODO Auto-generated method stub
		super.finish();
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		// TODO Auto-generated method stub
		super.onActivityResult(requestCode, resultCode, data);
		Logger.e("BetRecordActivity", "requestCode = " + requestCode + ", resultCode = " + resultCode);
		if (requestCode == 910 && resultCode == Activity.RESULT_OK) {
			setResult(Activity.RESULT_OK);
			this.finish();
		}
	};

}